package com.lanbu.web.controller.system;

import com.lanbu.system.domain.vo.DatasetIds;
import com.lanbu.system.domain.vo.DialogKnowledgeMapping;
import com.lanbu.system.service.impl.MappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/mapping")
public class MappingController {

    @Autowired
    private MappingService mappingService;

    // 保存映射
    @PostMapping("/save")
    public String saveMapping(@RequestBody DialogKnowledgeMapping dialogKnowledgeMapping) {
        mappingService.saveMapping(dialogKnowledgeMapping.getChatID(), dialogKnowledgeMapping.getDatasetId());
        return "Mapping saved successfully.";
    }

    // 获取知识库ID
    @PostMapping("/get")
    public DatasetIds getKnowledgeBaseId(@RequestBody DialogKnowledgeMapping dialogKnowledgeMapping) {
        String kbId = mappingService.getKnowledgeBaseId(dialogKnowledgeMapping.getChatID());

        DatasetIds datasetIds =new DatasetIds();
        datasetIds.setDatasetId(kbId);
        System.out.println(kbId);
        return datasetIds.getDatasetId() != null ? datasetIds: null;
    }
}
